home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
SETUP
/
US
/
CBUILDER
/
DATA.Z
/
BTSCLASS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-02-13
|
19KB
|
741 lines
//---------------------------------------------------------------------------
// Borland C++Builder
// Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
//---------------------------------------------------------------------------
// BtsClass.pas
//
// VCL Class Browser
//---------------------------------------------------------------------------
unit BtsClass;
interface
uses Windows, SysUtils, Classes, MIFiles, DB, DBTables, BtsConst, BDE;
const
fldnoNetName = 3; { USER table, Network Name field }
type
{ Exceptions }
EBts = class(Exception);
ENoRecords = class(EBts);
ESystemDown = class(EBts);
EInvalidField = class(EBts)
public
Field: TField;
constructor Create(AField: TField; const Msg: string);
end;
EMissingAttach = class(EInvalidField);
{ Notifications }
EDisplayOutline = class(Exception)
public
ItemCode: Double;
constructor Create(ACode: Double);
end;
{ TLookupList }
PStrItem = ^TStrItem;
TStrItem = record
FObject: TObject;
FCode: Integer;
FDesc: PChar;
FValue: string;
FString: string;
end;
TLookupList = class(TStrings)
private
List: TList;
FCoded: Boolean;
FUseDesc: Boolean;
FTableName: string;
protected
CodeSep: string;
DescSep: string;
function NewStrItem(const S: string): PStrItem;
procedure DisposeStrItem(P: PStrItem);
function Get(Index: Integer): string; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
procedure Put(Index: Integer; const S: string); override;
procedure PutObject(Index: Integer; AObject: TObject); override;
function GetValue(Index: Integer): string;
function GetDesc(Index: Integer): string;
function GetCode(Index: Integer): Integer;
function GetItem(Index: Integer): string;
public
constructor Create;
destructor Destroy; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: string); override;
procedure Clear; override;
function IndexOfValue(const S: string): Integer;
function IndexOfDesc(const S: string): Integer;
function IndexOfCode(ACode: Integer): Integer;
function IndexOfItem(const S: string): Integer;
function CodeToValue(ACode: Integer): string;
function ValueToCode(const AValue: string): Integer;
property Value[Index: Integer]: string read GetValue;
property Desc[Index: Integer]: string read GetDesc;
property Code[Index: Integer]: Integer read GetCode;
property Item[Index: Integer]: string read GetItem;
property UseDesc: Boolean read FUseDesc write FUseDesc;
property TableName: string read FTableName write FTableName;
property Coded: Boolean read FCoded;
end;
{ TBtsUser }
TBtsUser = class
private
FNetName: string;
FUserName: string;
FGroup: string;
FRights: TUserRights;
FRegistered: Boolean;
public
constructor Create(UserTab: TTable; GroupLook: TLookupList;
const DefRights: string);
procedure CheckRights(Value: TUserRights);
property Group: string read FGroup;
property NetName: string read FNetName;
property Rights: TUserRights read FRights;
property UserName: string read FUserName;
property Registered: Boolean read FRegistered write FRegistered;
end;
{ TFieldMap }
TFieldMap = class(TStringList)
private
function GetStatusValue(ResValue: Integer): Integer;
public
constructor Create(StatIni: TMemIniFile; const CfgSect: string);
property StatusValue[ResValue: Integer]: Integer read GetStatusValue;
end;
{ TCloneDataset }
TCloneDataset = class(TDBDataset)
private
FSourceHandle: HDBICur;
procedure SetSourceHandle(ASourceHandle: HDBICur);
protected
function CreateHandle: HDBICur; override;
public
property SourceHandle: HDBICur read FSourceHandle write SetSourceHandle;
end;
{ TCloneTable }
TCloneTable = class(TTable)
private
FSourceHandle: HDBICur;
procedure SetSourceHandle(ASourceHandle: HDBICur);
protected
function CreateHandle: HDBICur; override;
public
constructor CreateFromTable(AOwner: TComponent; Reset: Boolean);
procedure InitFromTable(SourceTable: TTable; Reset: Boolean);
end;
{ TQueryField }
TQueryField = class
protected
FQDType: TQueryDataType;
FFldNo: Integer;
FQRow: Integer;
FQText: string;
FFldName: string;
FLookupTableName: string;
public
LookupData: array[1..2] of TQueryField;
constructor Create(AQDType: TQueryDataType; AFldNo: Integer; AQText: string);
destructor Destroy; override;
procedure InitLookupData(LookupList: TLookupList;
const Example, CodeFldName, DescFldName: string; ARow, ACol: Integer);
property FldNo: Integer read FFldNo;
property FldName: string read FFldName write FFldName;
property QText: string read FQText write FQText;
property QRow: Integer read FQRow write FQRow;
property QDType: TQueryDataType read FQDType;
property LookupTableName: string read FLookupTableName write FLookupTableName;
end;
{ TQueryData }
TQueryData = class(TList)
private
function Get(Index: Integer): TQueryField;
public
procedure Empty;
destructor Destroy; override;
property Items[Index: Integer]: TQueryField read Get; default;
end;
{ TQBEQuery }
TCheckType = (ctNone, ctCheck, ctCheckPlus, ctCheckDesc, ctCheckGroup);
TQBEQuery = class(TQuery)
private
hQry: hDBIQry;
protected
function CreateHandle: HDBICur; override;
public
constructor Create(AOwner: TComponent); override;
procedure AddExpr(const TabName, FldName: string; Row: Integer;
CheckType: TCheckType; Expr: string);
end;
{ TOtlData }
TOtlData = class(TObject)
public
ProgName: PChar;
Tester: PChar;
HasChildren: Boolean;
constructor Create(PName, TName: PChar; ChildFlag: Boolean);
destructor Destroy; override;
end;
implementation
uses DBConsts;
{ EInvalidField }
constructor EInvalidField.Create(AField: TField; const Msg: string);
begin
Field := AField;
inherited Create(Msg);
end;
{ TDisplayOutline }
constructor EDisplayOutline.Create(ACode: Double);
begin
ItemCode := ACode;
end;
{ TLookupList }
constructor TLookupList.Create;
const
SCodeSep = '|';
SDescSep = ' - ';
begin
inherited Create;
List := TList.Create;
CodeSep := SCodeSep;
DescSep := SDescSep;
end;
destructor TLookupList.Destroy;
begin
if List <> nil then
begin
Clear;
List.Destroy;
end;
inherited Destroy;
end;
function TLookupList.NewStrItem(const S: string): PStrItem;
var
CodeSepPos: Integer;
ValLen: Integer;
begin
CodeSepPos := Pos(CodeSep, S);
FCoded := CodeSepPos > 0;
ValLen := Pos(DescSep, S) - 1;
if (ValLen > 0) and (CodeSepPos > 0) then
Dec(ValLen, CodeSepPos - 1 + Length(CodeSep));
Result := New(PStrItem);
if FCoded then
begin
Result^.FString := Copy(S, CodeSepPos + Length(CodeSep), Length(S));
Result^.FCode := StrToInt(Copy(S, 1, CodeSepPos - 1));
end else
begin
Result^.FString := S;
Result^.FCode := -1;
end;
with Result^ do
begin
FObject := nil;
if ValLen > 0 then
begin
{ Make a copy of the value part, so we can access it easily }
FValue := Copy(FString, 1 , ValLen);
{ And a pointer to only the description }
FDesc := @FString[ValLen + Length(DescSep) + 1];
end else
begin
FValue := FString;
FDesc := nil;
end;
end;
end;
procedure TLookupList.DisposeStrItem(P: PStrItem);
begin
P.FObject.Free;
Dispose(P);
end;
function TLookupList.Get(Index: Integer): string;
begin
Result := PStrItem(List[Index]).FString;
end;
function TLookupList.GetObject(Index: Integer): TObject;
begin
Result := PStrItem(List[Index]).FObject;
end;
function TLookupList.GetCount: Integer;
begin
Result